//============================================================================
// Name        : AlarmStatus.cpp
// Author      : Casey Kelso
// Copyright   : Kineticsproject.com (c) 2010
// Description : Alarm Status Class
// Created     : September 14th 2010
//============================================================================

#include "AlarmStatus.h"
#include <cstdlib>

AlarmStatus::AlarmStatus() : SYMBOL_ON('1'), SYMBOL_OFF('0'), SYMBOL_UNDEFINED('-'), beepMaximum(7), beepMinimum(1)
{


}

AlarmStatus::AlarmStatus(const AlarmStatus &rhs) : SYMBOL_ON('1'), SYMBOL_OFF('0'), SYMBOL_UNDEFINED('-'), beepMaximum(7), beepMinimum(1)
{
    this->ready             = rhs.ready;
    this->alarmBell         = rhs.alarmBell;
    this->alarmTriggered    = rhs.alarmTriggered;
    this->acPower           = rhs.acPower;
    this->armedAway         = rhs.armedAway;
    this->armedStay         = rhs.armedStay;
    this->backLight         = rhs.backLight;
    this->batteryLow        = rhs.batteryLow;
    this->chimeMode         = rhs.chimeMode;
    this->programmingMode   = rhs.programmingMode;
    this->valid             = rhs.valid;
    this->zonesBypassed     = rhs.zonesBypassed;
    this->unused            = rhs.unused;
}

AlarmStatus::~AlarmStatus()
{

}

AlarmStatus::eAlarmState AlarmStatus::getAlarmState(void)
{
    eAlarmState result;

    result = STATE_ALARM_UNKNOWN;

    if (STATE_ON == ready)
    {
        result = STATE_ALARM_READY;
    }
    else if (STATE_ON == armedAway)
    {
        result = STATE_ALARM_AWAY;
    }
    else if (STATE_ON == armedStay)
    {
        result = STATE_ALARM_STAY;
    }

    return(result);
}

AlarmStatus& AlarmStatus::operator=(const AlarmStatus &rhs)
{
	if (this != &rhs) // no self assignment
	{
		this->ready             = rhs.ready;
		this->alarmBell         = rhs.alarmBell;
		this->alarmTriggered    = rhs.alarmTriggered;
		this->acPower           = rhs.acPower;
		this->armedAway         = rhs.armedAway;
		this->armedStay         = rhs.armedStay;
		this->backLight         = rhs.backLight;
		this->batteryLow        = rhs.batteryLow;
		this->chimeMode         = rhs.chimeMode;
		this->programmingMode   = rhs.programmingMode;
		this->valid             = rhs.valid;
		this->zonesBypassed     = rhs.zonesBypassed;
		this->unused            = rhs.unused;
	}

    return *this;
}



void AlarmStatus::setAlarmStatusMessage(std::string statusString)
{
    static uint8_t tempBeeps = 0;
    beep = 0;

    setFieldState(ready,statusString[0]);
    setFieldState(armedAway,statusString[1]);
    setFieldState(armedStay, statusString[2]);
    setFieldState(backLight, statusString[3]);
    setFieldState(programmingMode, statusString[4]);

    tempBeeps = atoi(statusString.substr(5,1).c_str());

    if  ((tempBeeps >= 1) && (tempBeeps <= 7))
    {
        beep = tempBeeps;
    }

    setFieldState(zonesBypassed, statusString[6]);
    setFieldState(acPower, statusString[7]);
    setFieldState(chimeMode, statusString[8]);
    setFieldState(alarmTriggered, statusString[9]);
    setFieldState(alarmBell, statusString[10]);
    setFieldState(batteryLow, statusString[11]);
    setFieldState(unused, statusString[12]);
}

const string AlarmStatus::getAlarmStatusMessage(void)
{


    string statusString = "";

	return(statusString);

}

void AlarmStatus::setFieldState(eFieldState &fieldState, const unsigned char fieldStateSymbol)
{
	if (SYMBOL_ON == fieldStateSymbol)
	{
		fieldState = STATE_ON;
	}
	else if (SYMBOL_OFF == fieldStateSymbol)
	{
		fieldState = STATE_OFF;
	}
	else if (SYMBOL_UNDEFINED == fieldStateSymbol)
	{
		fieldState = STATE_UNDEFINED;	
	}	
}

bool AlarmStatus::isACPowerOn(void)
{
    return(STATE_ON == acPower);
}

bool AlarmStatus::isAlarmTriggered(void)
{
    return(STATE_ON == alarmTriggered);
}

bool AlarmStatus::isAlarmBell(void)
{
     return(STATE_ON == alarmBell);
}

bool AlarmStatus::isBatteryLow(void)
{
    return(STATE_ON == batteryLow);
}

